package com.lmx.repoDomain.repository;

import io.katharsis.repository.annotations.JsonApiResourceRepository;
import io.katharsis.repository.annotations.JsonApiSave;

import javax.annotation.PostConstruct;

import org.springframework.stereotype.Component;

import com.lmx.common.constants.ICommonConstants;
import com.lmx.repoDomain.exception.BusinessException;
import com.lmx.repoDomain.tmodel.SchemeRecord;

@JsonApiResourceRepository(SchemeRecord.class)
@Component
public class SchemeRecordRepository extends BaseRepository<SchemeRecord> {
	@PostConstruct
	public void init() {
		dslJpaService.setEntityClass(SchemeRecord.class);
	}

	@Override
	@JsonApiSave
	public SchemeRecord save(final SchemeRecord entity) {

		if (entity.getType() == null) {
			throw new BusinessException("",
					ICommonConstants.SCHEMEERROR.TYPE_NULL.lable(),
					"type不能为null");
		}
		if (entity.getCustomer() == null) {
			throw new BusinessException("",
					ICommonConstants.SCHEMEERROR.CUSTOMER_NULL.lable(),
					"customer不能为null");
		}
		return super.save(entity);
	}
}
